﻿/*
 *  Source code courtesy of the desktopWeb.CodePlex.com community project. See MS-PL license on Codeplex.com. 
 *  This is beta code not intended for a production application.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.Office.Interop.Excel;

namespace MyData.ExcelAddIn.SampleWorkflow
{
  //NEXT: OfficeClient subscriber concept
  class CellRendering
  {
    //NEXT: Extension methods
    //IClientRender
    public void Fill(System.Data.DataTable dataTable)
    {
      Worksheet sheet =(Worksheet)Globals.ThisAddIn.Application.ActiveSheet;

      //Header
      for (int i = 0; i < dataTable.Columns.Count; i++)
      {
        //NEXT: Excel extension method
        sheet.Cells[1, i + 1] = dataTable.Columns[i].ColumnName;
      }

      for (int r = 0; r < dataTable.Rows.Count; r++)
      {
        //NEXT: Excel extension method
        for (int c = 0; c < dataTable.Columns.Count; c++)
        {
          sheet.Cells[r + 2, c + 1] = dataTable.Rows[r][c];
        }

      }

    }
  }
}
